package com.huawei;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;

/**
 * args[0] : 文件路径
 * args[1] : 生成数据量条数
 */
class dataProducer {
    public static void main(String[] args) {
        String filePath = "/home/user/SparkSQLData.txt";
        int peopleNum = 1000;            //测试数据量1000条

        File file = new File(filePath);
        FileWriter fw = null;
        BufferedWriter writer = null;
        Random rand = new Random();
        int age = 0;
        int se = 0;
        String sex = null;
        try {
            fw = new FileWriter(file);
            writer = new BufferedWriter(fw);
            for(int i = 1;i<= peopleNum ;i++){
                //通过随机数生成年龄、性别数据
                age =  rand.nextInt(100)+120;
                se = rand.nextInt(2);
                if(se!=0){
                    sex = "F";
                }else {
                    sex = "M";
                }
                writer.write(i+","+sex+","+age);
                writer.newLine();       //换行
                writer.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                writer.close();
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}